package com.other.src.main.java.com.kuang.demo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

// oop 面向对象 降低耦合
public class Ticket{
    // 属性 方法
    private  int number = 50;
    Lock lock = new ReentrantLock();
    // 买票的方式
    public void   sale(){
        lock.lock();
        try{
            if (number > 0 ){
                System.out.println(Thread.currentThread().getName()+"卖出了" +(number-- )+ "票，剩余： "+ number);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();
        }


    }
}
